tools: remove xenstore entries on vchan server closure
authorOleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Thu, 29 Sep 2022 12:38:02 +0000 (14:38 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 29 Sep 2022 12:38:02 +0000 (14:38 +0200)
vchan server creates XenStore entries to advertise its event channel and
ring, but those are not removed after the server quits.
Add additional cleanup step, so those are removed, so clients do not try
to connect to a non-existing server.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Signed-off-by: Dmytro Semenets <dmytro_semenets@epam.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
tools/include/libxenvchan.h
tools/libs/vchan/init.c
tools/libs/vchan/io.c
tools/libs/vchan/vchan.h [new file with mode: 0644]

index d6010b145df299a62cf17f7318edebcdbc4a4e89..30cc73cf97e30d81732ad084eeac3838bb3841de 100644 (file)
@@ -86,6 +86,11 @@ struct libxenvchan {
        int blocking:1;
        /* communication rings */
        struct libxenvchan_ring read, write;
+       /**
+        * Base xenstore path for storing ring/event data used by the server
+        * during cleanup.
+        * */
+       char *xs_path;
 };
 
 /**
index c8510e6ce98a6ca5c6ea9174c044928527356fab..9195bd3b98759897d324bf0a712f7788be1e5865 100644 (file)
@@ -46,6 +46,8 @@
 #include <xen/sys/gntdev.h>
 #include <libxenvchan.h>
 
+#include "vchan.h"
+
 #ifndef PAGE_SHIFT
 #define PAGE_SHIFT 12
 #endif
@@ -251,6 +253,12 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base
        char ref[16];
        char* domid_str = NULL;
        xs_transaction_t xs_trans = XBT_NULL;
+
+       /* store the base path so we can clean up on server closure */
+       ctrl->xs_path = strdup(xs_base);
+       if (!ctrl->xs_path)
+               return -1; 
+
        xs = xs_open(0);
        if (!xs)
                goto fail;
@@ -298,6 +306,22 @@ retry_transaction:
        return ret;
 }
 
+void close_xs_srv(struct libxenvchan *ctrl)
+{
+       struct xs_handle *xs;
+
+       if (!ctrl->xs_path)
+               return;
+
+       xs = xs_open(0);
+       if (xs) {
+               xs_rm(xs, XBT_NULL, ctrl->xs_path);
+               xs_close(xs);
+       }
+
+       free(ctrl->xs_path);
+}
+
 static int min_order(size_t siz)
 {
        int rv = PAGE_SHIFT;
index da303fbc01caf5a167dfb9df98b469cb266d337b..1f201ad554f2dc050f45e63b92446d301fb76d89 100644 (file)
@@ -40,6 +40,8 @@
 #include <xenctrl.h>
 #include <libxenvchan.h>
 
+#include "vchan.h"
+
 #ifndef PAGE_SHIFT
 #define PAGE_SHIFT 12
 #endif
@@ -384,5 +386,7 @@ void libxenvchan_close(struct libxenvchan *ctrl)
                if (ctrl->gnttab)
                        xengnttab_close(ctrl->gnttab);
        }
+       if (ctrl->is_server)
+               close_xs_srv(ctrl);
        free(ctrl);
 }
diff --git a/tools/libs/vchan/vchan.h b/tools/libs/vchan/vchan.h
new file mode 100644 (file)
index 0000000..621016e
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * @file
+ * @section AUTHORS
+ *
+ * Copyright (C) 2021 EPAM Systems Inc.
+ *
+ * @section LICENSE
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @section DESCRIPTION
+ *
+ *  This file contains common libxenvchan declarations.
+ */
+#ifndef LIBVCHAN_H
+#define LIBVCHAN_H
+
+void close_xs_srv(struct libxenvchan *ctrl);
+
+#endif /* LIBVCHAN_H */